package com.base.social.config;

import java.io.Serializable;

/**
 * 授权登录配置类
 *
 * @author becker
 * @since 0.0.1
 */
public class AuthConfig implements Serializable {

    /**
     * 客户端id：对应各平台的appKey
     */
    private String clientId;

    /**
     * 客户端Secret：对应各平台的appSecret
     */
    private String clientSecret;

    /**
     * 登录成功后的回调地址
     */
    private String redirectUri;

    /**
     * 微信响应类型 默认code
     */
    private String responseType;

    /**
     * 微信授权作用域
     */
    private String scope;

    /**
     * 支付宝公钥：当选择支付宝登录时，该值可用
     * 对应“RSA2(SHA256)密钥”中的“支付宝公钥”
     */
    private String alipayPublicKey;

    /**
     * 是否需要申请unionid，目前只针对qq登录
     * 注：qq授权登录时，获取unionid需要单独发送邮件申请权限。如果个人开发者账号中申请了该权限，
     * 可以将该值置为true，在获取openId时就会同步获取unionId
     * 参考链接：http://wiki.connect.qq.com/unionid%E4%BB%8B%E7%BB%8D
     * <p>
     * 1.7.1版本新增参数
     */
    private boolean unionId;

    /**
     * Stack Overflow Key
     * <p>
     *
     * @since 1.9.0
     */
    private String stackOverflowKey;

    /**
     * 企业微信，授权方的网页应用ID
     *
     * @since 1.10.0
     */
    private String agentId;

    public AuthConfig(String clientId, String clientSecret, String redirectUri, String alipayPublicKey, boolean unionId,
                      String stackOverflowKey, String agentId) {
        this.clientId = clientId;
        this.clientSecret = clientSecret;
        this.redirectUri = redirectUri;
        this.alipayPublicKey = alipayPublicKey;
        this.unionId = unionId;
        this.stackOverflowKey = stackOverflowKey;
        this.agentId = agentId;
    }

    public AuthConfig() {}

    public static AuthConfigBuilder builder() {
        return new AuthConfigBuilder();
    }

    public String getClientId() {
        return this.clientId;
    }

    public String getClientSecret() {
        return this.clientSecret;
    }

    public String getRedirectUri() {
        return this.redirectUri;
    }

    public String getResponseType() {
        return responseType;
    }

    public String getScope() {
        return scope;
    }

    public String getAlipayPublicKey() {
        return this.alipayPublicKey;
    }

    public boolean isUnionId() {
        return this.unionId;
    }

    public String getStackOverflowKey() {
        return this.stackOverflowKey;
    }

    public String getAgentId() {
        return this.agentId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
    }

    public void setRedirectUri(String redirectUri) {
        this.redirectUri = redirectUri;
    }

    public void setResponseType(String responseType) {
        this.responseType = responseType;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public void setAlipayPublicKey(String alipayPublicKey) {
        this.alipayPublicKey = alipayPublicKey;
    }

    public void setUnionId(boolean unionId) {
        this.unionId = unionId;
    }

    public void setStackOverflowKey(String stackOverflowKey) {
        this.stackOverflowKey = stackOverflowKey;
    }

    public void setAgentId(String agentId) {
        this.agentId = agentId;
    }

    public static class AuthConfigBuilder {
        private String clientId;
        private String clientSecret;
        private String redirectUri;
        private String alipayPublicKey;
        private boolean unionId;
        private String stackOverflowKey;
        private String agentId;

        AuthConfigBuilder() {
        }

        public AuthConfig.AuthConfigBuilder clientId(String clientId) {
            this.clientId = clientId;
            return this;
        }

        public AuthConfig.AuthConfigBuilder clientSecret(String clientSecret) {
            this.clientSecret = clientSecret;
            return this;
        }

        public AuthConfig.AuthConfigBuilder redirectUri(String redirectUri) {
            this.redirectUri = redirectUri;
            return this;
        }

        public AuthConfig.AuthConfigBuilder alipayPublicKey(String alipayPublicKey) {
            this.alipayPublicKey = alipayPublicKey;
            return this;
        }

        public AuthConfig.AuthConfigBuilder unionId(boolean unionId) {
            this.unionId = unionId;
            return this;
        }

        public AuthConfig.AuthConfigBuilder stackOverflowKey(String stackOverflowKey) {
            this.stackOverflowKey = stackOverflowKey;
            return this;
        }

        public AuthConfig.AuthConfigBuilder agentId(String agentId) {
            this.agentId = agentId;
            return this;
        }

        public AuthConfig build() {
            return new AuthConfig(clientId, clientSecret, redirectUri, alipayPublicKey, unionId, stackOverflowKey, agentId);
        }

        public String toString() {
            return "AuthConfig.AuthConfigBuilder(clientId=" + this.clientId + ", clientSecret=" + this.clientSecret + ", redirectUri=" + this.redirectUri + ", alipayPublicKey=" + this.alipayPublicKey + ", unionId=" + this.unionId + ", stackOverflowKey=" + this.stackOverflowKey + ", agentId=" + this.agentId + ")";
        }
    }
}
